package com.bobamrz.frontend;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.security.InvalidParameterException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.bobamrz.db.CameraDAO;
import com.bobamrz.db.ConnectionManager;
import com.bobamrz.domain.DocCatalog;
import com.bobamrz.domain.DocType;
import com.bobamrz.domain.Document;
import com.bobamrz.domain.UserDTO;
import com.bobamrz.model.Camera;
import com.bobamrz.service.CatalogueService;
import com.bobamrz.service.DocStatusService;
import com.bobamrz.service.DocTypeService;
import com.bobamrz.service.DocumentService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

public class ClipboardServlet extends SecuredSuperServlet {
	
	private Logger log = Logger.getLogger(ClipboardServlet.class);

	/**
	 * 
	 */
	private static final long serialVersionUID = 461051363305070386L;
	
	private HeaderAndMenuDataLoader headerAndMenuDataLoader = new HeaderAndMenuDataLoader();

	protected void securedGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		headerAndMenuDataLoader.load(request);

		HttpSession session = request.getSession(false);
		List<Long> docIdsInClipboard = (List<Long>)session.getAttribute("clipboard");
		List<Document> docList;
		if(docIdsInClipboard == null || docIdsInClipboard.size() == 0) {
			docList = new ArrayList<Document>();
		} else {
			DocumentService docService = new DocumentService();
			docList = docService.getDocumentList(docIdsInClipboard);
		}
		request.setAttribute("docList", docList);
		
		request.setAttribute("pageToLoad", "/WEB-INF/pages/clipboard.jsp");
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/pages/mainPage.jsp");
		dispatcher.forward(request, response);
	}
	
}
